package oldCar;

import sun.text.normalizer.Trie;

import java.awt.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ling
 * Date: 2022-11-07
 * Time: 14:59
 */
public class newCarExample {
    static class Car {
        private Framework framework;
        public Car(Framework framework) {
            this.framework = framework;
        }
        public void init () {
            //依赖车身
            framework.init();
            System.out.println("车子启动");
        }
    }

    /**
     * 车身类
     */
    static class Framework {
        private Bottom bottom;
        public Framework(Bottom bottom) {
            this.bottom = bottom;
        }
        public void init() {
            //依赖底盘
            bottom.init();
            System.out.println("车身类启动");
        }
    }

    /**
     * 底盘类
     */
    static class Bottom {
        private Tire tire;
        private Bottom(Tire tire) {
            this.tire =tire;
        }
        public void init() {
            //依赖轮胎
            tire.init();
            System.out.println("底盘类启动");
        }
    }

    /**
     * 轮胎类
     */
    static class Tire {
        private int size =15;//轮胎尺寸
        private String color = "白色";
        public Tire (int size,String color) {
            this.size=size;
            this.color=color;
        }
        public Tire(int size) {
            this.size = size;
        }
        public void init() {
            System.out.println("轮胎尺寸"+size);
            System.out.println("轮胎颜色"+color);
        }
    }

    public static void main(String[] args) {
        Tire tire = new Tire(20);
       // Tire tire = new Tire(20,"红色");//这样控制反转式程序开发，就算后面添加需求要红色的轮胎，也可以直接在Tire上改即可而没必要全部类都改一遍
        Bottom bottom = new Bottom(tire);
        Framework framework = new Framework(bottom);
        Car car = new Car(framework);
        car.init();
    }
}
